package com.u3k.mid;

import com.u3k.app.mid.utils.statistics.StatisticsManager;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class ac {
    private static final String a = ac.class.getSimpleName();

    /*
    这个函数中，r1是so文件，r8是apk文件，从r1当中读取前16个字节，生成字符串，调用a函数获取加密方法
    然后生成加密流，把so文件当中的内容继续读取，通过加密流写入到apk文件

    r8 r0 r4 都是apk文件对应的文件名、File和文件流，r1是apk文件对应的加密流
    r7 r1 r2 都是sow文件对应的文件名、File和文件流
     */
    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static java.io.File a(java.lang.String r7, java.lang.String r8) {
        /*
        r3 = 0;
        r1 = new java.io.File;	 Catch:{ IOException -> 0x00fa, all -> 0x00ca }
        r1.<init>(r7);	 Catch:{ IOException -> 0x00fa, all -> 0x00ca }
        r0 = new java.io.File;	 Catch:{ IOException -> 0x00fa, all -> 0x00ca }
        r0.<init>(r8);	 Catch:{ IOException -> 0x00fa, all -> 0x00ca }
        r2 = r1.exists();	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        if (r2 == 0) goto L_0x0104;
    L_0x0011:
        r2 = r1.isFile();	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        if (r2 == 0) goto L_0x0104;
    L_0x0017:
        r2 = r0.getParentFile();	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        r2 = r2.exists();	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        if (r2 != 0) goto L_0x0028;
    L_0x0021:
        r2 = r0.getParentFile();	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        r2.mkdirs();	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
    L_0x0028:
        r0.createNewFile();	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        r2 = new java.io.FileInputStream;	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        r2.<init>(r1);	 Catch:{ IOException -> 0x0100, all -> 0x00ca }
        r1 = 16;
        r1 = new byte[r1];	 Catch:{ IOException -> 0x0107, all -> 0x010c }
        r4 = 0;
        r5 = 16;
        r2.read(r1, r4, r5);	 Catch:{ IOException -> 0x0107, all -> 0x010c }
        r5 = new java.lang.String;	 Catch:{ IOException -> 0x0107, all -> 0x010c }
        r5.<init>(r1);	 Catch:{ IOException -> 0x0107, all -> 0x010c }
        r4 = new java.io.FileOutputStream;	 Catch:{ IOException -> 0x0107, all -> 0x010c }
        r4.<init>(r0);	 Catch:{ IOException -> 0x0107, all -> 0x010c }
        r1 = new javax.crypto.CipherOutputStream;	 Catch:{ IOException -> 0x005d, all -> 0x00f7 }
        r3 = 2;
        r3 = a(r5, r3);	 Catch:{ IOException -> 0x005d, all -> 0x00f7 }
        r1.<init>(r4, r3);	 Catch:{ IOException -> 0x005d, all -> 0x00f7 }
        r3 = 1024; // 0x400 float:1.435E-42 double:5.06E-321;
        r3 = new byte[r3];	 Catch:{ IOException -> 0x005d, all -> 0x00f7 }
    L_0x0052:
        r5 = r2.read(r3);	 Catch:{ IOException -> 0x005d, all -> 0x00f7 }
        if (r5 < 0) goto L_0x0076;
    L_0x0058:
        r6 = 0;
        r1.write(r3, r6, r5);	 Catch:{ IOException -> 0x005d, all -> 0x00f7 }
        goto L_0x0052;
    L_0x005d:
        r1 = move-exception;
        r3 = r4;
    L_0x005f:
        r4 = "error=";
        com.u3k.mid.au.a(r4, r1);	 Catch:{ all -> 0x010a }
        r4 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();	 Catch:{ all -> 0x010a }
        r5 = com.u3k.mid.ae.a();	 Catch:{ all -> 0x010a }
        r4.logException(r5, r1);	 Catch:{ all -> 0x010a }
        r2.close();	 Catch:{ IOException -> 0x00a6 }
    L_0x0072:
        r3.close();	 Catch:{ IOException -> 0x00b8 }
    L_0x0075:
        return r0;
    L_0x0076:
        r1.close();	 Catch:{ IOException -> 0x005d, all -> 0x00f7 }
        r1 = r2;
        r3 = r4;
    L_0x007b:
        r1.close();	 Catch:{ IOException -> 0x0094 }
    L_0x007e:
        r3.close();	 Catch:{ IOException -> 0x0082 }
        goto L_0x0075;
    L_0x0082:
        r1 = move-exception;
        r2 = "error=";
        com.u3k.mid.au.a(r2, r1);
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();
        r3 = com.u3k.mid.ae.a();
        r2.logException(r3, r1);
        goto L_0x0075;
    L_0x0094:
        r1 = move-exception;
        r2 = "error=";
        com.u3k.mid.au.a(r2, r1);
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();
        r4 = com.u3k.mid.ae.a();
        r2.logException(r4, r1);
        goto L_0x007e;
    L_0x00a6:
        r1 = move-exception;
        r2 = "error=";
        com.u3k.mid.au.a(r2, r1);
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();
        r4 = com.u3k.mid.ae.a();
        r2.logException(r4, r1);
        goto L_0x0072;
    L_0x00b8:
        r1 = move-exception;
        r2 = "error=";
        com.u3k.mid.au.a(r2, r1);
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();
        r3 = com.u3k.mid.ae.a();
        r2.logException(r3, r1);
        goto L_0x0075;
    L_0x00ca:
        r0 = move-exception;
        r2 = r3;
    L_0x00cc:
        r2.close();	 Catch:{ IOException -> 0x00d3 }
    L_0x00cf:
        r3.close();	 Catch:{ IOException -> 0x00e5 }
    L_0x00d2:
        throw r0;
    L_0x00d3:
        r1 = move-exception;
        r2 = "error=";
        com.u3k.mid.au.a(r2, r1);
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();
        r4 = com.u3k.mid.ae.a();
        r2.logException(r4, r1);
        goto L_0x00cf;
    L_0x00e5:
        r1 = move-exception;
        r2 = "error=";
        com.u3k.mid.au.a(r2, r1);
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();
        r3 = com.u3k.mid.ae.a();
        r2.logException(r3, r1);
        goto L_0x00d2;
    L_0x00f7:
        r0 = move-exception;
        r3 = r4;
        goto L_0x00cc;
    L_0x00fa:
        r0 = move-exception;
        r1 = r0;
        r2 = r3;
        r0 = r3;
        goto L_0x005f;
    L_0x0100:
        r1 = move-exception;
        r2 = r3;
        goto L_0x005f;
    L_0x0104:
        r1 = r3;
        goto L_0x007b;
    L_0x0107:
        r1 = move-exception;
        goto L_0x005f;
    L_0x010a:
        r0 = move-exception;
        goto L_0x00cc;
    L_0x010c:
        r0 = move-exception;
        goto L_0x00cc;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.u3k.mid.ac.a(java.lang.String, java.lang.String):java.io.File");
    }

    private static Cipher a(String str, int i) {
        Cipher instance;
        Exception e;
        try {
            AlgorithmParameterSpec ivParameterSpec = new IvParameterSpec("0102030405060708".getBytes());
            Key secretKeySpec = new SecretKeySpec(str.getBytes(), "AES");
            instance = Cipher.getInstance("AES/CBC/PKCS5Padding");
            try {
                instance.init(i, secretKeySpec, ivParameterSpec);
            } catch (Exception e2) {
                e = e2;
                LogUtils.a("error=", e);
                StatisticsManager.getInstance().logException(ae.a(), e);
                return instance;
            }
        } catch (Exception e3) {
            e = e3;
            instance = null;
            LogUtils.a("error=", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
            return instance;
        }
        return instance;
    }
}
